<template>
  <div class='container'>
    <!-- 审核 -->
    <el-dialog title="题目预览" :visible="dialogCheck" width="30%" @close="handlerClose">
      <div>
        <el-radio v-model="radio" label="1">通过</el-radio>
        <el-radio v-model="radio" label="2">拒绝</el-radio>
      </div>
      <el-input type="textarea" v-model="detail" style="margin-top:20px" placeholder="请输入审核意见"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handlerClose">取 消</el-button>
        <el-button type="primary" @click="handelSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { choiceCheck, choicePublish } from '@/api/hmmm/questions.js'
export default {
  name: 'Check',
  data () {
    return {
      radio: '1',
      detail: ''
    }
  },
  props: {
    // 弹窗显示
    dialogCheck: {
      type: Boolean,
      required: true
    },
    // 审核id
    id: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 功能1.---关闭按钮
    handlerClose () {
      this.$emit('update:dialogCheck', false)
    },
    // 功能2.---确定按钮
    async handelSubmit () {
      if (!this.detail) {
        this.$message.warning('请填写审核意见')
      }
      // 调用接口更改审核
      try {
        const ret = await choiceCheck({
          id: this.id,
          chkState: Number(this.radio),
          chkRemarks: this.detail
        })
        if (ret.status === 200) {
          if (Number(this.radio) === 1) {
            const res = await choicePublish({
              id: this.id,
              publishState: 1
            })
            if (res.status === 200) {
              this.localQusetList()
            }
          } else if (Number(this.radio) === 2) {
            const info = await choicePublish({
              id: this.id,
              publishState: 2
            })
            if (info.status === 200) {
              this.localQusetList()
            }
          }
        }
        // 1.关闭弹窗
        this.handlerClose()
        // 通知父组件刷新列表
        this.$parent.localQusetList()
      } catch {
        this.$message.error('试题审核出错')
      }
    }
  }
}
</script>

<style scoped lang='less'></style>
